package Announce;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTextPane;

import gui.ClientInfo;
import gui.Connect;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class ThongBaoForm extends JFrame {
	private static final long serialVersionUID = 1L;

	public Connect gui;
	
	
	public JPanel contentPane;
	public JTextPane txtThgBao;
	public JScrollPane scrollPane;
	public JButton btnThgBao;

	public ThongBaoForm(Connect cc) {
		setTitle("Nh\u1EADp Th\u00F4ng B\u00E1o Cho Client");
		gui = cc;
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(450, 300);
		setLocationRelativeTo(null);
		setResizable(false);
		contentPane = new JPanel();
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtThgBao = new JTextPane();
		txtThgBao.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		scrollPane = new JScrollPane(txtThgBao);
		scrollPane.setBounds(10, 11, 424, 210);
		contentPane.add(scrollPane);
		
		btnThgBao = new JButton("G\u1EEDi Th\u00F4ng b\u00E1o");
		btnThgBao.setBounds(170, 232, 119, 23);
		btnThgBao.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				for(ClientInfo ci : gui.mht.dsClient) {
					try {
						ObjectOutputStream output = new ObjectOutputStream(ci.announceSocket.getOutputStream());
						output.writeUTF(txtThgBao.getText().trim());
						output.flush();
						output.reset();
						setVisible(false);
						dispose();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		});
		contentPane.add(btnThgBao);
	}
}
